package com.heima.jedis.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * <p>
 * JedisConnectionFactory
 * </p>
 *
 * @author flyduck
 * @since 2025-02-28
 */
public class JedisConnectionFactory {
    private static JedisPool jedisPool;

    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(8);
        jedisPoolConfig.setMaxIdle(8);//最大空闲连接数
        jedisPoolConfig.setMinIdle(0);//最小空闲连接数
        jedisPoolConfig.setMaxWaitMillis(1000);//没有连接可用时，最多等待时长

        jedisPool = new JedisPool(jedisPoolConfig,
                "192.168.1.102",
                6379,
                1000);
    }

    public static Jedis getJedis(){
        return jedisPool.getResource();
    }
}
